//
//  PersonalViewController.m
//  PerfectWorld
//
//  Created by dllo on 16/9/23.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "PersonalViewController.h"
#import "PerSonalTableViewCell.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
@interface PersonalViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)UIView *headerView;
@property (nonatomic, strong)UIImageView *titleImage;
@property (nonatomic, strong)NSMutableArray *CellArr;
@end

@implementation PersonalViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"返回, 实心"] style:UIBarButtonItemStylePlain target:self action:@selector(clickLeftBtn:)];
    self.CellArr = [NSMutableArray arrayWithObjects:@"个性签名:", @"昵称:", @"手机:", @"所在地:", @"设计师认证", @"账号密码           修改", nil];
    [self creatSubView];
}
- (void)creatSubView {
    self.headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height / 3)];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    [self.view addSubview:_tableView];
    _tableView.tableHeaderView = _headerView;
     [_tableView registerNib:[UINib nibWithNibName:@"PerSonalTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"personCell"];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [user objectForKey:@"dic"];
    NSDictionary *dicUser = [dic objectForKey:@"user"];
    NSDictionary *dicUserImage = [dicUser objectForKey:@"userImage"];
    NSString *strImage = [dicUserImage objectForKey:@"large"];
    UIImageView *backImage = [[UIImageView alloc] initWithFrame:_headerView.frame];
    [backImage sd_setImageWithURL:[NSURL URLWithString:strImage] placeholderImage:nil];
    [_headerView addSubview:backImage];
        UIBlurEffect *blur = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
    UIVisualEffectView *effectview = [[UIVisualEffectView alloc] initWithEffect:blur];
    effectview.alpha = 0.65;
    effectview.frame = _headerView.frame;
    [backImage addSubview:effectview];
    self.navigationController.hidesBarsOnSwipe = NO;
    self.titleImage = [[UIImageView alloc]init];
        [_titleImage sd_setImageWithURL:[NSURL URLWithString:strImage] placeholderImage:nil];
    _titleImage.layer.cornerRadius = 30;
    [effectview addSubview:_titleImage];
    [_titleImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(60);
        make.centerX.mas_equalTo(_headerView.mas_centerX);
        make.top.mas_equalTo(60);
    }];
    UIButton *concernbtn = [UIButton buttonWithType:UIButtonTypeCustom];
    concernbtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [concernbtn setTitle:@"我的关注" forState:UIControlStateNormal];
    [self.view addSubview:concernbtn];
    [concernbtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(70);
        make.height.mas_equalTo(30);
        make.top.mas_equalTo(_titleImage.mas_bottom).offset(15);
        make.right.mas_equalTo (_titleImage.mas_left);
    }];
    UILabel *concernLabel = [[UILabel alloc] init];
    concernLabel.font = [UIFont systemFontOfSize:15];
    concernLabel.textColor = [UIColor whiteColor];
    concernLabel.text = @"0";
    [self.view addSubview:concernLabel];
    [concernLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.height.mas_equalTo(30);
        make.top.mas_equalTo(concernbtn.mas_bottom).offset(5);
        make.centerX.mas_equalTo(concernbtn.mas_centerX);
    }];
    UIButton *fansBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    fansBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [fansBtn setTitle:@"我的粉丝" forState:UIControlStateNormal];
    [self.view addSubview:fansBtn];
    [fansBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.top.width.mas_equalTo(concernbtn);
        make.left.mas_equalTo(_titleImage.mas_right);
    }];
    UILabel *fansLabel = [[UILabel alloc] init];
    fansLabel.textColor = [UIColor whiteColor];
    fansLabel.text = @"0";
    fansLabel.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:fansLabel];
    [fansLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.top.mas_equalTo(concernLabel);
        make.centerX.mas_equalTo(fansBtn.mas_centerX);
    }];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _CellArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PerSonalTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"personCell"];
    cell.textLabel.text = _CellArr[indexPath.row];
    return cell;
}
- (void)clickLeftBtn:(UIBarButtonItem *)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
